package com.sgb.member.util;

import android.text.TextUtils;

import com.swgk.core.util.ArrayUtil;
import com.swgk.core.util.NumberUtil;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;

public class MVehicleConstant {

    public static String getIsDumpStr(Integer isDump) {
        if (isDump == null) {
            return "";
        }
        switch (isDump) {
            case 0:
                return "非自卸";
            case 1:
                return "自卸";
            default:
                return "";
        }
    }

    public static String getTrim0Str(Double value) {
        if (value == null) {
            return "";
        }

        return NumberUtil.trim0(value);
    }

    public static String getTrim0Str(String value) {
        if (value == null) {
            return "";
        }

        return NumberUtil.trim0(value);
    }

    public static String getInvoiceStr(String invoice) {
        if (TextUtils.isEmpty(invoice)) {
            return "";
        }

        if ("1".equals(invoice)) {
            return "不开发票";
        }
        if ("2".equals(invoice)) {
            return "普通发票";
        }
        if ("3".equals(invoice)) {
            return "增值税专用发票";
        }
        return "";

    }

    /**
     * 对车长数据排序 去重
     *
     * @param datas
     * @return
     */
    public static List<CommonPopEntity> sortCarLength(List<CommonPopEntity> datas) {
        if (ArrayUtil.isNotNullAndEmpty(datas)) {
            Collections.sort(datas, (o1, o2) -> {
                if (null != o1.getTypeName() && null != o2.getTypeName()) {
                    double len1 = com.swgk.core.util.NumberUtil.convertToDouble(o1.getTypeName().replace("米", ""));
                    double len2 = com.swgk.core.util.NumberUtil.convertToDouble(o2.getTypeName().replace("米", ""));
                    double result = len1 - len2;
                    if (result > 0) {
                        return 1;
                    } else if (result < 0) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
                return 0;
            });
        }

        datas.removeAll(Collections.singleton(null));
        LinkedHashSet<CommonPopEntity> set = new LinkedHashSet<>();
        set.addAll(datas);
        datas = new ArrayList<>(set);
        return datas;
    }
}
